<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%--
  Created by IntelliJ IDEA.
  User: 武
  Date: 2021/7/6
  Time: 8:48
  To change this template use File | Settings | File Templates.
--%>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0 ,minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">

    <title>结算页面</title>

    <link href="../AmazeUI-2.4.2/assets/css/amazeui.css" rel="stylesheet" type="text/css" />

    <link href="../basic/css/demo.css" rel="stylesheet" type="text/css" />
    <link href="../css/cartstyle.css" rel="stylesheet" type="text/css" />

    <link href="../css/jsstyle.css" rel="stylesheet" type="text/css" />

    <script type="text/javascript" src="../js/address.js"></script>
    <script type="text/javascript" src="../js/jsAddress.js"></script>
</head>

<body>

<!--顶部导航条 -->

<div class="am-container header">
    <ul class="message-l">
        <div class="topMessage">
            <div class="menu-hd">
            </div>
        </div>
    </ul>
    <ul class="message-r">
        <div class="topMessage home">
            <div class="menu-hd"><a href="/home" target="_top" class="h">商城首页</a></div>
        </div>
        <div class="topMessage my-shangcheng">
            <div class="menu-hd MyShangcheng"><a href="/personCenter" target="_top"><i
                    class="am-icon-user am-icon-fw"></i>个人中心</a></div>
        </div>
        <div class="topMessage mini-cart">
            <div class="menu-hd"><a id="mc-menu-hd" href="/cartList" target="_top"><i
                    class="am-icon-shopping-cart  am-icon-fw"></i><span>购物车</span></a>
            </div>
        </div>
        <div class="topMessage favorite">
            <div class="menu-hd"><a href="/toCollection" target="_top"><i
                    class="am-icon-heart am-icon-fw"></i><span>收藏夹</span></a></div>
        </div>
    </ul>
</div>

<!--悬浮搜索框-->

<div class="nav white">
    <div class="logo"><img src="../images/logo.png" /></div>
    <div class="logoBig">
        <li><img src="../images/logobig.png" /></li>
    </div>

    <div class="search-bar pr">
        <a name="index_none_header_sysc" href="#"></a>
    </div>
</div>

<div class="clear"></div>
<div class="concent">
    <!--地址 -->
    <div class="paycont">
        <div class="address">
            <h3>确认收货地址 </h3>
            <div class="control">
                <div class="tc-btn createAddr theme-login am-btn am-btn-danger">使用新地址</div>
            </div>
            <div class="clear"></div>
            <ul>
                <div class="per-border"></div>
<c:if test="${defaultShopAddresses!=null}">
    <c:forEach items="${defaultShopAddresses}" var="defaultShopAddress">
                <c:if test="${shopAddresses!=null}">
                    <c:forEach items="${shopAddresses}" var="shopAddress">
                        <c:if test="${shopAddress.shopId == defaultShopAddress.shopId}">
                            <li class="user-addresslist defaultAddr">
                        </c:if>
                        <c:if test="${shopAddress.shopId != defaultShopAddress.shopId}">
                            <li class="user-addresslist">
                        </c:if>
                            <div class="address-left">
                                <div class="user DefaultAddr">

									<span class="buy-address-detail">
                                        <input class="shopId" value="${shopAddress.shopId}" hidden/>
										<span class="buy-user">${shopAddress.receiverName} </span>
										<span class="buy-phone">${shopAddress.receiverMobile}</span>
									</span>
                                </div>
                                <div class="default-address DefaultAddr">
                                    <span class="buy-line-title buy-line-title-type">收货地址：</span>
                                    <span class="buy--address-detail">
										<span class="province">${shopAddress.receiverProvince}</span>
										<span class="city">${shopAddress.receiverCity}</span>
										<span class="dist">${shopAddress.receiverDistrict}</span>
										<span class="street">${shopAddress.receiverAddress}</span>
									</span>

                                    </span>
                                </div>
                                <c:if test="${shopAddress.defaultTag==0}">
                                    <ins class="deftip">默认地址</ins>
                                </c:if>
                            </div>
                            <div class="address-right">
                                <span class="am-icon-angle-right am-icon-lg"></span>
                            </div>
                            <div class="clear"></div>

                            <div class="new-addr-btn">
                                <c:if test="${shopAddress.defaultTag!=0}">
                                    <a href="/setDefaultTag?shopId=${shopAddress.shopId}&checked=${checked}">设为默认</a>
                                    <span class="new-addr-bar">|</span>
                                </c:if>
                                <a href="/delShopAddress?shopId=${shopAddress.shopId}&checked=${checked}">删除</a>
                            </div>

                        </li>
                    </c:forEach>
                </c:if>
    </c:forEach>
</c:if>
            </ul>
            <div class="clear"></div>
        </div>
        <!--物流 -->
        <div class="logistics">
            <h3>选择物流方式</h3>
            <ul class="op_express_delivery_hot">
                <li id="yuantong" data-value="yuantong" class="OP_LOG_BTN  "><i class="c-gap-right"
                                                                                style="background-position:0px -468px"></i>圆通<span></span></li>
                <li id="shentong" data-value="shentong" class="OP_LOG_BTN  "><i class="c-gap-right"
                                                                                style="background-position:0px -1008px"></i>申通<span></span></li>
                <li id="yunda" data-value="yunda" class="OP_LOG_BTN  "><i class="c-gap-right"
                                                                          style="background-position:0px -576px"></i>韵达<span></span></li>
                <li id="zhongtong" data-value="zhongtong" class="OP_LOG_BTN op_express_delivery_hot_last "><i
                        class="c-gap-right" style="background-position:0px -324px"></i>中通<span></span></li>
                <li id="shunfeng" data-value="shunfeng" class="OP_LOG_BTN  op_express_delivery_hot_bottom"><i
                        class="c-gap-right" style="background-position:0px -180px"></i>顺丰<span></span></li>
            </ul>
        </div>
        <div class="clear"></div>

        <!--支付方式-->
        <div class="logistics">
            <h3>选择支付方式</h3>
            <ul class="pay-list">
                <li class="pay taobao"><img src="../images/zhifubao.jpg" />支付宝<span></span></li>
            </ul>
        </div>
        <div class="clear"></div>

        <!--订单 -->
        <div class="concent">
            <div id="payTable">
                <h3>确认订单信息</h3>
                <div class="cart-table-th">
                    <div class="wp">

                        <div class="th th-item">
                            <div class="td-inner">商品信息</div>
                        </div>
                        <div class="th th-price">
                            <div class="td-inner">单价</div>
                        </div>
                        <div class="th th-amount">
                            <div class="td-inner">数量</div>
                        </div>
                        <div class="th th-sum">
                            <div class="td-inner">金额</div>
                        </div>
                        <div class="th th-oplist">
                            <div class="td-inner">配送费用</div>
                        </div>

                    </div>
                </div>
                <div class="clear"></div>

                <c:forEach items="${carts}" var="cart">
                    <tr class="item-list">
                        <div class="bundle  bundle-last">

                            <div class="bundle-main">
                                <ul class="item-content clearfix">
                                    <div class="pay-phone">
                                        <li class="td td-item">
                                            <div class="item-pic">
                                                <a href="#" class="J_MakePoint">
                                                    <img src="${cart.pictureUrl}"
                                                         class="itempic J_ItemImg"></a>
                                            </div>
                                            <div class="item-info">
                                                <div class="item-basic-info">
                                                    <a href="#" class="item-title J_MakePoint"
                                                       data-point="tbcart.8.11">${cart.proName}</a>
                                                </div>
                                            </div>
                                        </li>
                                        <li class="td td-info">
                                            <div class="item-props">
                                                <span class="sku-line">口味：${cart.flavor}</span>
                                                <span class="sku-line">包装：${cart.pack}</span>
                                            </div>
                                        </li>
                                        <li class="td td-price">
                                            <div class="item-price price-promo-promo">
                                                <div class="price-content">
                                                    <em class="J_Price price-now">${cart.price}</em>
                                                </div>
                                            </div>
                                        </li>
                                    </div>
                                    <li class="td td-amount">
                                        <div class="amount-wrapper ">
                                            <div class="item-amount ">
                                                <span class="phone-title">购买数量</span>
                                                <div class="sl">
                                                    <input class="text_box" name="" type="text" value="${cart.quantity}"
                                                           style="width:30px; border: none;" />
                                                </div>
                                            </div>
                                        </div>
                                    </li>
                                    <li class="td td-sum">
                                        <div class="td-inner">
                                            <em tabindex="0" class="J_ItemSum number">${cart.amount}</em>
                                        </div>
                                    </li>
                                    <li class="td td-oplist">
                                        <div class="td-inner">
                                            <span class="phone-title">配送方式</span>
                                            <div class="pay-logis">
                                                <c:if test="${freight==0}">
                                                    快递-<b class="sys_item_freprice">包邮</b>
                                                </c:if>
                                                <c:if test="${freight!=0}">
                                                    快递-共<b class="sys_item_freprice">${freight}</b>元
                                                </c:if>
                                            </div>
                                        </div>
                                    </li>

                                </ul>
                                <div class="clear"></div>

                            </div>
                        </div>
                    </tr>
                    <div class="clear"></div>
                </c:forEach>
            </div>
        </div>
        <div class="clear"></div>
        <div class="pay-total">
            <div class="clear"></div>
        </div>
        <!--含运费小计 -->
        <div class="buy-point-discharge ">
            <p class="price g_price ">
                合计（含运费） <span>¥</span><em class="pay-sum">${productPrice} + ${freight}</em>
            </p>
        </div>

        <!--信息 -->
        <div class="order-go clearfix">
            <div class="pay-confirm clearfix">
                <div class="box">
                    <div tabindex="0" id="holyshit267" class="realPay"><em class="t">实付款：</em>
                        <span class="price g_price ">
									<span>¥</span> <em class="style-large-bold-red " id="J_ActualFee">${sumPrice}</em>
								</span>
                    </div>

                    <div id="holyshit268" class="pay-address">
                        <c:if test="${defaultShopAddresses!=null}">
                            <c:forEach items="${defaultShopAddresses}" var="defaultShopAddress">
                                <p class="buy-footer-address">
                                    <span class="buy-line-title buy-line-title-type">寄送至：</span>
                                    <span class="buy--address-detail">
                                            <span class="province">${defaultShopAddress.receiverProvince}</span>
                                            <span class="city">${defaultShopAddress.receiverCity}</span>
                                            <span class="dist">${defaultShopAddress.receiverDistrict}</span>
                                            <span class="street">${defaultShopAddress.receiverAddress}</span>
                                        </span>
                                    </span>
                                </p>
                                <p class="buy-footer-address">
                                    <span class="buy-line-title">收货人：</span>
                                    <span class="buy-address-detail">
                                            <span class="buy-user">${defaultShopAddress.receiverName} </span>
                                            <span class="buy-phone">${defaultShopAddress.receiverMobile}</span>
                                        </span>
                                </p>
                            </c:forEach>
                        </c:if>
                    </div>
                </div>

                <div id="holyshit269" class="submitOrder">
                    <div class="go-btn-wrap">
                        <a id="J_Go" href="#" class="btn-go" tabindex="0" title="点击此按钮，提交订单">提交订单</a>
                    </div>
                </div>
                <div class="clear"></div>
            </div>
        </div>
    </div>

    <div class="clear"></div>
</div>
</div>
<div class="footer">
    <div class="footer-hd">
        <p>
            <b>|</b>
            <a href="# ">商城首页</a>
            <b>|</b>
            <a href="# ">支付宝</a>
            <b>|</b>
            <a href="# ">物流</a>
        </p>
    </div>
    <div class="footer-bd ">
        <p>
            <a href="# ">合作伙伴</a>
            <a href="# ">联系我们</a>
            <a href="# ">网站地图</a>
        </p>
    </div>
</div>
</div>
<div class="theme-popover-mask"></div>
<div class="theme-popover">

    <!--标题 -->
    <div class="am-cf am-padding">
        <div class="am-fl am-cf"><strong class="am-text-danger am-text-lg">新增地址</strong> / <small>Add
            address</small></div>
    </div>
    <hr />

    <div class="am-u-md-12">
        <form class="am-form am-form-horizontal">

            <div class="am-form-group">
                <label for="user-name" class="am-form-label">收货人</label>
                <div class="am-form-content">
                    <input type="text" id="user-name" placeholder="收货人"/>
                </div>
            </div>

            <div class="am-form-group">
                <label for="user-phone" class="am-form-label">手机号码</label>
                <div class="am-form-content">
                    <input id="user-phone" placeholder="手机号必填" type="text" pattern="^1[3|4|5|7|8][0-9]{9}$"/>
                </div>
            </div>

            <div class="am-form-group">
                <label for="user-phone" class="am-form-label">所在地</label>
                <div class="am-form-content address">
                    <select data-am-selected id="cmbProvince" name="cmbProvince"></select>
                    <select data-am-selected id="cmbCity" name="cmbCity"></select>
                    <select data-am-selected id="cmbArea" name="cmbArea"></select>
                </div>
            </div>

            <div class="am-form-group">
                <label for="user-intro" class="am-form-label">详细地址</label>
                <div class="am-form-content">
                    <textarea class="" rows="3" id="user-intro" placeholder="输入详细地址"></textarea>
                    <small>100字以内写出你的详细地址...</small>
                </div>
            </div>

            <div class="am-form-group theme-poptit">
                <div class="am-u-sm-9 am-u-sm-push-3">
                    <div id="saveAddress" class="am-btn am-btn-danger">保存</div>
                    <div id="cancel" class="am-btn am-btn-danger close">取消</div>
                </div>
            </div>
        </form>
    </div>
</div>
<div class="clear"></div>
</body>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-3.4.1.min.js"></script>
<script type="text/javascript">

    // 省市区联动
    addressInit('cmbProvince', 'cmbCity', 'cmbArea');

    $(function () {
        // 保存按钮功能
        $("#saveAddress").click(function () {
            var receiverName = $("#user-name").val();
            if(receiverName == null || receiverName ==""){
                alert("收货人不能为空，请重新输入！！！");
                return false;
            }
            var receiverMobile = $("#user-phone").val();
            if(receiverMobile == null || receiverMobile ==""){
                alert("手机号码不能为空，请重新输入！！！");
                return false;
            }
            var receiverProvince = $("#cmbProvince").val();
            var receiverCity = $("#cmbCity").val();
            var receiverDistrict = $("#cmbArea").val();
            var receiverAddress = $("#user-intro").val();
            if(receiverAddress == null || receiverAddress ==""){
                alert("详细地址不能为空，请重新输入！！！");
                return false;
            }
            addShopAddress(receiverName,receiverMobile,receiverProvince,receiverCity,receiverDistrict,receiverAddress);

            // 隐藏并置空增加收货地址界面
            $(".theme-popover").hide();
            $(".theme-popover-mask").hide();
            $("#user-name").val("");
            $("#user-phone").val("");
            $("#user-intro").val("");
            alert("添加地址成功！！！");
        });

        // 手机号码区域失去焦点时进行格式判定
        $("#user-phone").blur(function () {
            var phone = $("#user-phone").val();
            checkTel(phone);
        });

        function checkTel(phone) {
            var pattern = /^1[3|4|5|7|8][0-9]{9}$/;
            if (!pattern.test(phone)) {
                alert("请输入合法手机号");
                $("#user-phone").val("");
                return false;
            }
            return true;
        }

        // 取消按钮功能
        $("#cancel").click(function () {
            $("#user-name").val("");
            $("#user-phone").val("");
            $("#user-intro").val("");
        });

        // 选中地址更改地址卡片内容功能
        $(".user-addresslist").click(function () {
            var shopId = $(this).find(".shopId").val();
            location.href = "/showShopAddress?shopId=" + shopId + "&checked=" + ${checked};
        });

        // 获取物流名称
        var logisticsName = "";
        $("#yuantong").click(function () {
            logisticsName = "圆通";
        });
        $("#shentong").click(function () {
            logisticsName = "申通";
        });
        $("#yunda").click(function () {
            logisticsName = "韵达";
        });
        $("#zhongtong").click(function () {
            logisticsName = "中通";
        });
        $("#shunfeng").click(function () {
            logisticsName = "顺丰";
        });

        // 获取支付方式名称
        var payType = "";
        $(".pay").click(function () {
            payType = "支付宝";
        });

        // 提价订单功能
        $("#J_Go").click(function () {

            var province = $(".province").text();

            if(province == ""){
                alert("请选择您的收货地址！！！");
                return false;
            }

            if(logisticsName == ""){
                alert("请选择您心仪的物流公司！！！");
                return false;
            }
            if(payType == ""){
                alert("请选择支付方式！！！");
                return false;
            }

            location.href = "/insertOrders?logisticsName=" + logisticsName + "&checked=" + ${checked};
        });

        // 增加地址功能
        function addShopAddress(receiverName,receiverMobile,receiverProvince,receiverCity,receiverDistrict,receiverAddress) {
            $.getJSON("/addAddress", {"receiverName":receiverName, "receiverMobile":receiverMobile,
                "receiverProvince":receiverProvince, "receiverCity":receiverCity,
                "receiverDistrict":receiverDistrict, "receiverAddress":receiverAddress}, function (data) {
                if(data){
                    location.href = "/showShopAddress?checked=" + ${checked};
                } else {
                    alert("添加地址失败，请重新输入！！！");
                    $("#user-name").val("");
                    $("#user-phone").val("");
                    $("#user-intro").val("");
                }
            })
        }
    })
</script>
</html>
